from django.db import models

from django.contrib.auth import get_user_model
from article.models import ArticleModel

# 从系统中获取自己定义的user表
User = get_user_model()


class LikeModel(models.Model):
    """
    用户喜欢博客模型
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    blog = models.ForeignKey(ArticleModel, on_delete=models.CASCADE, verbose_name='博客')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '喜欢操作'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.id


class UserFavorite(models.Model):
    """
    用户收藏模型
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    fav_id = models.ForeignKey(ArticleModel, on_delete=models.CASCADE, verbose_name='关联博客id')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '用户收藏'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user


class UserClickArticle(models.Model):
    """
    用户点赞操作模型
    """
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    blog = models.ForeignKey(ArticleModel, on_delete=models.CASCADE, verbose_name='关联的博客')
    create_at = models.DateTimeField(auto_now_add=True, null=False, verbose_name='添加时间')
    update_at = models.DateTimeField(auto_now=True, null=False, verbose_name='修改时间')

    class Meta(object):
        verbose_name = '用户点赞'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user
